from sqlalchemy import create_engine
import pandas as pd


def get_mysql(user, password, ip, db, port=3306):
    engine_str = f'mysql+pymysql://{user}:{password}@{ip}:{port}/{db}'
    engine = create_engine(engine_str, encoding='utf-8')
    return engine


if __name__ == '__main__':
    client = get_mysql('root', '*', '*', '*')
    # df = pd.read_sql_query('select title from user_data', client)
    # df.to_csv('like.txt', sep='\t', index=False)
    df = pd.read_sql_query("SELECT title from new a  where a.pubDate>'2019-06-10 07:10:57' and  a.title not in (select t.title from user_data t)", client)
    df.to_csv('nplike.txt', sep='\t', index=False)